import { changeHistoryInfoApi } from "@/api/configCenter/warehouseEntryChannel";
import { message } from "ant-design-vue";

export default function OperationHook(state: Base.GeneraDataType) {
  const { formState, emit, loading } = state;
  const submitHandle = () => {
    loading.value = true;
    const params = {
      ...formState.value
    };

    params.itemList = formState.value.itemList.map((t: any) => {
      return {
        ...t,
        countryList: t.countryList.map((r: any) => {
          return {
            countryId: r
          };
        })
      };
    });
    changeHistoryInfoApi(params)
      .then((res: any) => {
        const { code } = res;
        if (code === 200) {
          message.success("操作成功!");
          emit("historySubmit");
          emit("update:visible", false);
        }
      })
      .finally(() => (loading.value = false));
  };
  const cancelHandle = () => {
    emit("update:visible", false);
  };
  return {
    submitHandle,
    cancelHandle
  };
}
